package traveldream.ejb.entities;

import java.io.Serializable;
import java.lang.String;

import javax.persistence.*;

import travelDream.ejb.DTOs.HotelDTO;

/**
 * Entity implementation class for Entity: Hotel
 *
 */
@Entity
@Table(name="HOTEL")
@NamedQueries({ @NamedQuery(name= Hotel.FIND_ALL, query="SELECT h FROM Hotel h WHERE h.prenotabile = true"),
	@NamedQuery(name= Hotel.FIND_BY_CITTA, query = "SELECT h FROM Hotel h WHERE h.citta = :citta AND h.prenotabile = true"),
	@NamedQuery(name= Hotel.FIND_BY_CITTA_NOME, query = "SELECT h FROM Hotel h WHERE h.citta = :citta AND h.nome = :nome")
})
public class Hotel implements Serializable {

	//Utilizzabili dagli EJB per creare le queries
		public static final String FIND_ALL = "Hotel.findAll";
		public static final String FIND_BY_CITTA = "Hotel.findByCitta";
		public static final String FIND_BY_CITTA_NOME = "Hotel.FindByCittaNome";
	   
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int hotelID;
	private String nome;
	private String citta;
	private int numStelle;
	private boolean prenotabile;
	
	private static final long serialVersionUID = 1L;

	//costruttore default
	public Hotel() {
		super();
		prenotabile = true; //nuovo prodotto base nasce come "prenotabile"
	}   
	
	//costruttore per Entities da voloDTO
	public Hotel(HotelDTO hotel) {
		this.nome = hotel.getNome();
		this.citta = hotel.getCitta();
		this.numStelle = Integer.parseInt(hotel.getNumStelle());  //String > int
		this.prenotabile = true; //nuovo prodotto base nasce come "prenotabile"
	}
	
	//getters e setters
	public int getHotelID() {
		return this.hotelID;
	}

	public void setHotelID(int hotelID) {
		this.hotelID = hotelID;
	}   
	
	public String getNome() {
		return this.nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}
	
	public String getCitta() {
		return this.citta;
	}

	public void setCitta(String citta) {
		this.citta = citta;
	}   
	public int getNumStelle() {
		return this.numStelle;
	}

	public void setNumStelle(int numStelle) {
		this.numStelle = numStelle;
	}
	
	public boolean isPrenotabile() {
		return prenotabile;
	}

	public void setPrenotabile(boolean prenotabile) {
		this.prenotabile = prenotabile;
	}

	//converte in HotelDTO, utilizzabile da EJB per mandare dati al Web ("prenotabile" non serve)
	public HotelDTO entityToDTO(){
		HotelDTO tmp = new HotelDTO();
		tmp.setHotelId(hotelID);
		tmp.setNome(nome);
		tmp.setCitta(citta);
		tmp.setNumStelle(String.valueOf(numStelle));
		return tmp;
	}
	
	
   
}
